package com.work.cos.web.controller.api.pr;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.work.cos.domain.entity.pr.PrOrderDetailEntity;
import com.work.cos.domain.vo.ComServiceResVo;
import com.work.cos.service.interfc.pr.IPrOrderService;

@RestController
@RequestMapping("/api/order")
public class PrOrderApiController {

	private static Logger LOGGER = LoggerFactory.getLogger(PrOrderApiController.class);
	
	@Autowired
	private IPrOrderService orderService;

	/**
	 * 查看订单状态
	 * @return
	 */
	@PostMapping(value = "/status")
	public ComServiceResVo queryFirstList(@RequestParam Integer orderStatus,@RequestParam  Long userId){
		LOGGER.debug("query first type... ");
		return ComServiceResVo.returnList(orderService.getListByOrderStatus(orderStatus , userId));
	}
	
	/**
	 * 更新订单状态
	 * @return
	 */
	@PostMapping(value = "/status/update")
	public ComServiceResVo toStatusUpdate(@RequestParam Integer orderStatus,
			@RequestParam  String userId,@RequestParam  Long id){
		LOGGER.debug("status update ... orderStatus={}" , orderStatus);
		boolean flag = orderService.toStatusUpdate(orderStatus, userId, id);
		if(flag){
			
			return ComServiceResVo.returnSuccessStatus();
		}
		return ComServiceResVo.returnErrorMessage("订单状态异常");
	}
	
	/**
	 * 取消订单状态
	 * @return
	 */
	@PostMapping(value = "/status/cancel")
	public ComServiceResVo toStatusCancel(@RequestParam Integer isCancel,
			@RequestParam  String userId,@RequestParam  Long id){
		LOGGER.debug("status update ... cancel={}" , isCancel);
		boolean flag = orderService.toStatusCancel(isCancel, userId, id);
		if(flag){
			
			return ComServiceResVo.returnSuccessStatus();
		}
		return ComServiceResVo.returnErrorMessage("订单取消异常");
	}
	
	/**
	 * 提交订单
	 * @return
	 */
	@PostMapping(value = "/add")
	public ComServiceResVo add(List<PrOrderDetailEntity> orderList){
		LOGGER.debug("order add ... ");
		return ComServiceResVo.returnErrorMessage("订单取消异常");
	}
}
